package com.dxq.oa.pub;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class OaResult<T> {

    private String code;
    private String msg;
    private T data;


    /**构建返回对象*/
    public static<T> OaResult build(String code,String msg,T data){
        return new OaResult(code,msg,data);
    }

    /**包含数据的正确请求信息*/
    public static<T> OaResult getSuccessData(String msg,T data){
        OaResult oaResult = new OaResult();
        oaResult.code=PubConst.SUCCESS_CODE;
        oaResult.msg=msg;
        oaResult.data=data;
        return oaResult;
    }

    /**只包含msg和code的返回对象*/
    public static<T> OaResult getSuccess(String msg){
        OaResult oaResult = new OaResult();
        oaResult.code=PubConst.SUCCESS_CODE;
        oaResult.msg=msg;
        return oaResult;
    }

    /**错误对象*/
    public static OaResult error(String mdg){
        OaResult oaResult = new OaResult();
        oaResult.code=PubConst.ERROR_CODE;
        oaResult.msg=mdg;
        return oaResult;
    }

}
